package xyz.syyrjx.provider.load;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import xyz.syyrjx.entity.SyyrjxRpcRemoteAddress;
import xyz.syyrjx.provider.conf.SyyrjxRpcProviderConfiguration;

/**
 * @author 大地崩坏苍蝇兽
 * @date 2023/1/19 - 18:47
 */
public class SyyrjxRpcProviderEnvironmentSetAware{
    private final static Logger LOGGER = LoggerFactory.getLogger(SyyrjxRpcProviderEnvironmentSetAware.class);

    public static void environmentInit(ApplicationContext applicationContext) throws BeansException {
        LOGGER.debug("初始化环境");
        SyyrjxRpcProviderConfiguration configuration = applicationContext.getBean(SyyrjxRpcProviderConfiguration.class);

        //设置本机地址
        SyyrjxRpcRemoteAddress address = new SyyrjxRpcRemoteAddress();
        address.setHost(configuration.getHost());
        address.setPort(configuration.getPort());
        SyyrjxRpcProviderConfiguration.setLocal(address);

        //设置配置类
        SyyrjxRpcProviderConfiguration.setConfiguration(configuration);
    }
}
